package network.TCP.conversation;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * @author zxl
 * @version 1.0
 * @date 2021/10/22 9:15
 * 客户端
 */
public class Client {

    private static Socket socket;
    private static OutputStream outputStream;

    public static void main(String[] args) {
        try {
            //要知道服务端的地址
            InetAddress byName = InetAddress.getByName("192.168.74.1");
            //创建链接
            socket = new Socket(byName,9999);
            //发消息  IO流
            outputStream = socket.getOutputStream();
            outputStream.write("你好".getBytes());

        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (outputStream!=null){
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (socket!=null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
